package com.cy.pj.sys.web.controller;

import com.cy.pj.common.util.PageUtil;
import com.cy.pj.notice.web.pojo.JsonResult;
import com.cy.pj.sys.pojo.SysLog;
import com.cy.pj.sys.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/log/")
public class SySLogController {

    @Autowired
    private SysLogService sysLogService;

    @GetMapping ("{id}")
    public JsonResult doFindById(Long id){
        return new JsonResult(sysLogService.findById(id));
    }

    @DeleteMapping("{ids}")
    public JsonResult doDeleteById(Long ids){
        sysLogService.deleteById(ids);
       return new JsonResult("delete ok");
    }

    @GetMapping
    public JsonResult doFindLogs(SysLog sysLog){
//        PageInfo pageInfo=
//                PageUtil.startPage()
//                .doSelectPageInfo(
//                        ()->sysLogService.findLogs(sysLog));
//        return new JsonResult(pageInfo);
        return new JsonResult(
                PageUtil.startPage()//启动分页查询拦截
                        .doSelectPageInfo(()->//分页查询日志信息
                sysLogService.findLogs(sysLog)
        ));
    }
    @PostMapping
    public JsonResult doSaveLogs(SysLog sysLog){
        sysLogService.saveLog(sysLog);
        return new JsonResult("save ok");
    }
}
